package com.wongoing.test;

import org.junit.After;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockHttpSession;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;

/**
 * 功能说明：WebService单元测试基类
 * 修改说明：
 * @author zhenglibing
 * @date 2017年10月14日 下午9:31:29
 * @version V0.1
 */
@RunWith(SpringJUnit4ClassRunner.class)		//告诉spring怎样执行
@WebAppConfiguration		//标明是web应用测试
@ContextConfiguration(locations={"classpath:spring.xml", "classpath:spring-mvc.xml"})		//load配置文件
public class MyWebServiceTestCase<T> {
	protected T webService = null;
	private MockMvc mockMvc;
	private MockHttpSession session;
	
	@Autowired
	protected void setWebService(T webService) {
		this.webService = webService;
		this.mockMvc = MockMvcBuilders.standaloneSetup(this.webService).build();
		this.session = new MockHttpSession();
	}
	
	protected MockMvc getMockMvc() {
		return this.mockMvc;
	}
	
	protected MockHttpSession getSession() {
		return this.session;
	}

	public MyWebServiceTestCase() {
		
	}
	
	@Before
	public void before() {
		System.out.println("-----------------------------------------");
	}
	
	@After
	public void after() {
		System.out.println("-----------------------------------------");
	}
}
